﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using jSLApp.Client.ApplicationBase;
using jSLApp.Client.MainService;
using jSLCore.Client.Presentation.ApplicationContainer;
using jSLCore.Client.Presentation.BaseControl.Selection;

namespace jSLApp.Client.Forms
{
    public partial class MusicList : SelectControl
    {
        public MusicList()
        {
            InitializeComponent();
        }

        public override void LoadInitialData()
        {
            Search();
        }

        private void Search()
        {
            DoWork("Поиск...",(sender, args) =>
                                  {
                                      args.Result = Communication.Proxy.SearchMusicList(args.String);
                                  },(o, eventArgs) =>
                                                        {
                                                            if(eventArgs.Error==null)
                                                            {
                                                                grid.ItemsSource = (IEnumerable<Music>) eventArgs.Result;
                                                            }
                                                        },txt.Text);
        }

        public IEnumerable<Music> Musics
        {
            get { return (IEnumerable<Music>) grid.ItemsSource; }
            set
            {
                grid.ItemsSource = value;
               // Bind();
            }
        }

        public override ISelectableGrid GetSelectableGrid()
        {
            return grid;
        }

        public override bool IsStandartOkCancelEnabledWhenNotSelectable
        {
            get { return false; }
        }

        protected override void AcceptButtonClicked()
        {
            Search();
        }


    }
}
